package database.bean.example;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import database.bean.example.User;

/**
 * Bean Camera.
 * @author Guillaume Pocas & Jean-Fraçois Augé
 */
@Entity
@Table(name = "cameras")
public class Camera {

	@Id
	@GeneratedValue
	@Column(name = "id")
	private int cam_id;
	
	@Column(name = "nom", nullable = false, updatable = false, unique = true)
	private String cam_name;
	
	@Column(name = "adresse_ip", nullable = false, updatable = false, unique = true)
	private String cam_ip;
	
	@ManyToOne
    @JoinColumn(name = "id_serveursite")
	private SiteServer serveur_site;
	
	@ManyToOne
	@JoinColumn(name = "id_serveurstockage")
	private StorageServer serveur_stockage;
	
	@Column(name = "marque")
	private String cam_marque;
	
	@Column(name = "description")
	private String cam_description;
	
	// priorite int
	@Column(name = "priorite")
	private int cam_priorite;
	
	@OneToMany(mappedBy="cameras")
    private Set<Video> videos;
	
	@OneToMany(mappedBy="cameras")
    private Set<CameraPlanning> cameraPlannings;
	
	// implémentation différente?
	@ManyToMany(mappedBy="cameras", cascade = {CascadeType.ALL})
    private Set<User> users = new HashSet<User>();
	
	/**
	 * Constructeur vide.
	 */
	public Camera() {}
	
	/**
	 * Créer une nouvelle Camera.
	 * @param name
	 * @param ip
	 */
	public Camera(String name, String ip) {
		this.cam_name = name;
		this.cam_ip = ip;
	}
	
	/**
	 * Créer une nouvelle Camera.
	 * @param name
	 * @param ip
	 * @param marque
	 * @param descr
	 */
	public Camera(String name, String ip, String marque, String descr) {
		this.cam_name = name;
		this.cam_ip = ip;
		this.cam_marque = marque;
		this.cam_description = descr;
	}
	
	public Camera(String name, String ip, String marque, String descr, int priorite, SiteServer site) {
		this.cam_name = name;
		this.cam_ip = ip;
		this.cam_marque = marque;
		this.cam_description = descr;
		this.cam_priorite = priorite;
		this.serveur_site = site;
	}
	
	public int getCam_id() { return cam_id; }
	public void setCam_id(int cam_id) { this.cam_id = cam_id; }

	public String getCam_ip() { return cam_ip; }
	public void setCam_ip(String cam_ip) { this.cam_ip = cam_ip; }
	
	public SiteServer getSite() { return serveur_site; }
	public void setSite(SiteServer site) { this.serveur_site = site; }
	
	public Set<Video> getVideos() { return videos; }
	public void setVideos(Set<Video> videos) { this.videos = videos; }
	
	public String getCam_name() {	return cam_name;	}
	public void setCam_name(String cam_name) { this.cam_name = cam_name;	}
	
	public StorageServer getStorageServer() { return serveur_stockage;	}
	public void setStorageServer(StorageServer storageServer) {	this.serveur_stockage = storageServer;	}
	
	public String getCam_marque() {	return cam_marque;	}
	public void setCam_marque(String cam_marque) { this.cam_marque = cam_marque;	}
	
	public String getCam_description() { return cam_description;	}
	public void setCam_description(String cam_description) { this.cam_description = cam_description;	}
	
	public int getCam_priorite() { return cam_priorite; }
	public void setCam_priorite(int cam_priorite) { this.cam_priorite = cam_priorite; }

	public Set<CameraPlanning> getCameraPlannings() { return cameraPlannings;	}
	public void setCameraPlannings(Set<CameraPlanning> cameraPlannings) { this.cameraPlannings = cameraPlannings;	}
	
	public Set<User> getUsers() { return users; }
	public void setUsers(Set<User> users) { this.users = users; }

	/**
	 * Ajout un nouvel utilisateur à la camera.
	 */
	public void addUser(User user) {
		getUsers().add(user);
		user.getCameras().add(this);
	}
	
	@Override
	public String toString(){ return getCam_name();	}
	
}